<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: java.js.php 497 2014-01-30 16:40:52Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 497 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2014-01-30 16:40:52 +0000 (Thu, 30 Jan 2014) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

include('includes/application_top.php');
include(DIR_WS_CLASSES.'class.cacheFile.php');
$js = new chacheFile('js');

echo "/* direct */\n";
echo "function $"."D(msg){console.debug(msg);};\n";
//include JS aus template
$js_source_path = 'templates/'.CURRENT_TEMPLATE.'/javascript/';
if(file_exists($js_source_path.CURRENT_TEMPLATE.'.general.js'))
	$js->setJS($js_source_path.CURRENT_TEMPLATE.'.general.js');


if($_GET['ajax'] == '1')
	$js->setJS('cache/_cache_js_xajax.js');

$js_source_path = 'includes/javascript/js/';

$js->setJS($js_source_path.'submenu.js');
$js->setJS($js_source_path.'jquery.class.js');
$js->setJS($js_source_path.'jquery.hash.js');
$js->setJS($js_source_path.'itd.jquery.plugins.js');
$js->setJS($js_source_path.'itd.utils.js');
$js->setJS($js_source_path.'dhtmlx.message.js');
$js->setJS($js_source_path.'wz_tooltip.js');

if (isset($_GET['add'])) {
  $short_utils = array();
  foreach($_GET['add'] as $addItem) {
    if ($addItem == 'jTab') $short_utils[] = $addItem;
    if ($addItem == 'jScroll') $short_utils[] = $addItem;
    if ($addItem == 'popuplayer') $short_utils[] = $addItem;

    if ($addItem == 'jCarousel');
      $js->setJS($js_source_path.'jquery.carousel.js');

		if ($addItem == 'nivoSlider')
      $js->setJS($js_source_path.'jquery.nivo.slider.js');

		if ($addItem == 'prettyPhoto') {
			echo "$(document).ready(function(){ $('a[rel^=prettyPhoto]').prettyPhoto(); });\n";
			$js->setJS($js_source_path.'jquery.prettyPhoto.js');
		}

    if ($addItem == 'konfigurator' || $addItem == 'konfigurator_just_layer') {
      // echo at the bottom - last content
    }
  }
  if(count($short_utils) > 0)
		$js->setJS($js_source_path.'itd.utils.js.php', 'false');

}

if($_GET['page'] != 'login_offline.php') {
  //$js->setJS('admin/includes/javascript/jquery-ui-1.8.16.custom.min.js');
	//$js->setJS($js_source_path.'jquery-ui-1.9.2-min.js');
  //$js->setJS($js_source_path.'jquery-ui-1.9.2-min.js');
  
	$js->setJS($js_source_path.'jquery.scroll_to.min.js');
	$js->setJS($js_source_path.'main.js');
	$js->setJS($js_source_path.'filter.js.php', 'false');
}

$js->setJS($js_source_path.'jquery.autobox.js');

if(CATEGORY_TYPE == 'expand')
	$js->setJS($js_source_path.'menu.js');
	
if($_GET['page'] == 'product_info.php' || (SITE_OVERLAYS == 'true') || $overlay) {
	$js->setJS($js_source_path.'jquery.prettyPhoto.js');
}

if($_GET['bs'] == 'slider' || $_GET['sb'] == 'slider' || $_GET['wn'] == 'slider' || $_GET['lv'] == 'slider' || $_GET['bl'] == 'slider')
	$js->setJS($js_source_path.'jquery.scroller.min.js.php', 'false');

if($_GET['bs'] == 'fader' || $_GET['sb'] == 'fader' || $_GET['wn'] == 'fader' || $_GET['lv'] == 'fader' || $_GET['bl'] == 'fader')
	$js->setJS($js_source_path.'jquery.innerfade.js.php', 'false');

if(isset($_GET['sbac']) && $_GET['sbac'])
	$js->setJS($js_source_path.'autocomplete.js.php', 'false');

if(isset($_GET['cmg']) && $_GET['cmg'] == 'yes')
	$js->setJS($js_source_path.'jquery.megamenu.js');

if($_GET['msg'] == '1')
	$js->setJS($js_source_path.'jquery.gritter.min.js');

if(isset($_GET['nt']) && $_GET['nt'] == 'true')
	$js->setJS($js_source_path.'jquery.tickertype.min.js');

if($_SESSION['cart']->count_contents() > 0 && SCROLL_BOX_CART == 'true' && $_GET['page'] != 'checkout.php')
	$js->setJS($js_source_path.'box_shopping_cart.js');

if(isset($_GET['box']) && $_GET['box'] == 'admin')
	$js->setJS($js_source_path.'box_admin.js');

switch($_GET['page']) { 
    case 'product_info.php':
	      $js->setJS($js_source_path.'itd.options.js');

        if(SOCIAL_BUTTON == '2click') $js->setJS($js_source_path.'jquery.socialshareprivacy.min.js');
//        $js->setJS($js_source_path.'jquery.ui.datepicker-'.$_GET['lc'].'.js');
        $js->setJS($js_source_path.'jquery.tallest.js');
        $js->setJS($js_source_path.'product_info.js.php', 'false');
        $js->setJS($js_source_path.'jquery.ad-gallery.js.php', 'false');
        
        if($_SESSION['customers_status']['customers_status_write_reviews'] != 0) {
            $js->setJS($js_source_path.'jquery.rating.pack.js');
            $js->setJS($js_source_path.'rating_form_check.js.php', 'false');
        }
        
        $js->setJS($js_source_path.'jQuery.tools.min.js');

        break;

    case 'index.php':
    case 'products_new.php':
    case 'product_filter.php':
    case 'shopping_cart.php':
    case 'specials.php':
    case 'taglisting.php':
        $js->setJS($js_source_path.'jquery.tallest.js');
        $js->setJS($js_source_path.'jquery.lazyload.min.js');
        $js->setJS($js_source_path.'jquery.zoomer.min.js');
        $js->setJS($js_source_path.'jquery.ajax_tooltip.js');
        $js->setJS($js_source_path.'product_lists.js');
        if(!$browser->isRobot() && CATEGORIE_INFINITE_SCROLLING == 'true' && isset($_GET['ct']) && $_GET['ct'] > 0)
        	$js->setJS($js_source_path.'jquery.infinitescroll.min.js');
        /*
        if(isset($_SESSION['customer_id']) && $_SESSION['customer_id'] == 1 && $_SESSION['customers_status']['customers_status_id'] == 0) {
        	$js->setJS('admin/includes/wysiwyg/js/elrte.min.js', 'false');
        	$js->setJS('admin/includes/wysiwyg/js/i18n/elrte.'.$_SESSION['language_code'].'.js');
			$js->setJS($js_source_path.'admin_inline_edit.js');
		}
		*/
        break;
   
    case 'blog.php':
        if(BLOG_STAND_ALONE == 'true')
        	$js->setJS($js_source_path.'blog.js');
        break;

    case 'login.php':
        $js->setJS($js_source_path.'login_form.js');

    case 'create_account.php':
    case 'create_guest_account.php':
        $js->setJS($js_source_path.'get_zones.js.php');
        $js->setJS($js_source_path.'jquery.infieldlabel.js');
        echo " $(document).ready(function(){ $('label').inFieldLabels(); });";
				break;

    case 'advanced_search_result.php':
    	$js->setJS($js_source_path.'jquery.tallest.js');
    	$js->setJS($js_source_path.'jquery.zoomer.min.js');
        $js->setJS($js_source_path.'jquery.ajax_tooltip.js');
        $js->setJS($js_source_path.'product_lists.js');
        $js->setJS($js_source_path.'jquery.lazyload.min.js');
        $js->setJS($js_source_path.'advanced_search.js.php');
        break;

    case 'checkout.php':
        $js->setJS($js_source_path.'checkout.js.php', 'false');
        break;

    case FILENAME_PRODUCT_REVIEWS_WRITE:
        $js->setJS($js_source_path.'jquery.rating.pack.js');
        $js->setJS($js_source_path.'rating_form_check.js.php');
        break;
}

if(isset($_GET['sl']) && $_GET['sl'] == 'true' && !isset($_GET['pid'])) {
	$getSettings = $db->db_query("SELECT 
										configuration_key, configuration_value 
									FROM 
										".TABLE_SLIDER_SETTINGS);
	while(!$getSettings->EOF) {
		if(is_numeric($getSettings->fields['configuration_value']) OR $getSettings->fields['configuration_value'] == 'true' OR $getSettings->fields['configuration_value'] == 'false')
			$_POST['sl_s'][] = $getSettings->fields['configuration_key'].':'.$getSettings->fields['configuration_value'];
		else
			$_POST['sl_s'][] = $getSettings->fields['configuration_key'].":\"".$getSettings->fields['configuration_value']."\"";
		$getSettings->MoveNext();
	}
	$js->setJS($js_source_path.'jquery.easing-1.3.pack.js');
	$js->setJS($js_source_path.'jquery.timers-1.2.js');
	$js->setJS($js_source_path.'jquery.slider.js');
	$js->setJS($js_source_path.'slider_settings.js.php', 'false');
}

if(GOOGLE_ANAL_ON == 'true' && GOOGLE_ANAL_CODE !='')
	$js->setJS($js_source_path.'google_analytics.js.php', 'false');

if(!isset($_SESSION['customer_id']))
	$js->setJS($js_source_path.'login.js');
	
if(CSS_BUTTON_ACTIVE != 'true' && CSS_BUTTON_ACTIVE != 'text')
	$js->setJS($js_source_path.'hover_button.js');


header("Cache-Control: public, must-revalidate, max-age=3600, post-check=3600, pre-check=3600");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Content-type:text/javascript;charset:UTF-8");
header('Connection: Keep-Alive'); 
header('Keep-Alive: timeout=300');
echo $js->outputJS();

if (isset($_GET['add'])) {
  foreach($_GET['add'] as $addItem) {
    if ($addItem == 'konfigurator' || $addItem == 'konfigurator_just_layer') {
      include_once(DIR_WS_CLASSES.'class.product_konfigurator.php');
	    $konfigurator = new product_konfigurator($_GET['pID']);
      if ($addItem == 'konfigurator')
        $konfigurator->print_js();
      else if ($addItem == 'konfigurator_just_layer')
        $konfigurator->print_js_just_layer();
    }
  }
}

